<template>
  <div class="app-container">

    <div class="customer_card_1">

<!--      <div style="font-size: 30px;font-weight: bold;margin: 0 20px 20px 0;">账户余额:{{ balance }}元</div>-->

      <el-form :model="queryParams2" ref="queryForm" :inline="true" label-width="100px" size="small">
        <el-form-item label="选择时间范围" prop="carNo">
          <el-date-picker
            v-model="time"
            type="daterange"
            value-format="yyyy-MM-dd"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期">
          </el-date-picker>
        </el-form-item>

        <el-form-item>
          <el-button type="primary" icon="el-icon-search" @click="refreshList">搜索</el-button>
          <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>
<!--      <el-button type="primary" size="mini" @click="goRecord">充值及消费记录</el-button>-->
    </div>

<!--    <el-row :gutter="10" class="mb8">-->
<!--      <el-col :span="1.5">-->
<!--        <el-button type="primary" size="mini" @click="handleQueryIllegal">违章查询</el-button>-->
<!--      </el-col>-->
<!--    </el-row>-->
    <div class="custom_card">

      <el-tabs v-model="activeName" type="card">
        <el-tab-pane label="工单" name="first"><!--/消费记录-->
          <div>
            <el-table v-loading="loading" :data="basicList" stripe
                      :header-cell-style="{ background: '#eef1f6', color: '#606266' }" border>
              <el-table-column label="工单号" align="center" prop="workOrderNo" />
              <el-table-column label="查询方式" align="center">
                <template v-slot="{ row }">
                  {{ row.submitType | submitType }}
                </template>
              </el-table-column>
              <el-table-column label="查询车辆" align="center">
                <template v-slot="{ row }">
                  {{ row.remark | filterNull }}
                </template>
              </el-table-column>
              <el-table-column label="提交人" align="center" prop="commitMan" />
              <el-table-column label="提交时间" align="center" prop="commitTime" />
              <el-table-column label="处理状态" align="center" prop="belongingStoreName">
                <template slot-scope="scope">
                  {{ scope.row.processingStatus == 2 ? '已处理' : '未处理' }}
                </template>
              </el-table-column>
              <el-table-column label="处理时间" align="center" prop="processingTime" />
<!--              <el-table-column label="本次消费(元)" align="center" prop="cost" />
              <el-table-column label="消费后余额(元)" align="center" prop="balance" />-->
              <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="160">
                <template slot-scope="scope">
                  <el-button size="mini" type="text" @click="handleDetail(scope.row)">查看</el-button>
                </template>
              </el-table-column>
            </el-table>

            <div style="background-color: #fff;padding-bottom: 10px; margin-top: 10px;">
              <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
                          @pagination="getList" />
            </div>
          </div>
        </el-tab-pane>
<!--        <el-tab-pane label="充值记录" name="second">
          <div>
            <el-table v-loading="loading2" :data="recordList" stripe
                      :header-cell-style="{ background: '#eef1f6', color: '#606266' }" border>
              <el-table-column label="充值前金额(元)" align="center" prop="changeBeforeAmount" />
              <el-table-column label="充值金额(元)" align="center" prop="operatingAmount" />
              <el-table-column label="充值后金额(元)" align="center" prop="changeAfterAmount" />
              <el-table-column label="充值时间" align="center" prop="createTime" />

            </el-table>

            <div style="background-color: #fff;padding-bottom: 10px; margin-top: 10px;">
              <pagination v-show="total2 > 0" :total="total2" :page.sync="queryParams2.pageNum" :limit.sync="queryParams2.pageSize"
                          @pagination="getRecordList" />
            </div>
          </div>

        </el-tab-pane>-->
      </el-tabs>


    </div>

    <!-- 充值消费记录 -->
    <record-list ref="recordList"></record-list>
    <!-- 详情 -->
    <illegal-detail ref="illeaglDetail"></illegal-detail>
    <!-- 新增违章工单 -->
    <add-illegal-order ref="addIllegalOrder" @success="refreshList"></add-illegal-order>
  </div>
</template>

<script>
import * as api from '@/api/car/illegal';
import RecordList from './components/recordList.vue';
import IllegalDetail from './components/illegalDetail.vue';
import AddIllegalOrder from './components/addIlleaglOrder.vue';
import {accountBalanceRecordList} from "@/api/car/illegal";
export default {
  name: 'Basic',
  components: {
    RecordList,
    IllegalDetail,
    AddIllegalOrder

  },
  data() {
    return {
      // 账户余额
      balance: 0.00,
      // 加载标识
      loading: false,
      loading2: false,
      // 总条数
      total: 0,
      // 车辆列表表格数据
      basicList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        carModelId: null,
        carNo: null,
        belongingStoreId: null,
        locatedStoreId: null,
        repairStatus: null,
        carStatus: null,
        carModelName: null,
      },
      queryParams2:{
        pageNum: 1,
        pageSize: 10,
        type:1,
        startDate:null,
        endDate:null
      },
      total2:0,
      recordList:[],
      showDetail: false,
      activeName:'first',
      time:'',
    }
  },
  created() {
    this.getAccountInfo();
    this.getList()
    this.getRecordList();
  },
  methods: {
    // 刷新工单
    refreshList() {
      if (this.time) {
        this.queryParams.startDate = this.time[0]
        this.queryParams.endDate = this.time[1]
        this.queryParams2.startDate = this.time[0]
        this.queryParams2.endDate = this.time[1]
      } else {
        this.queryParams.startDate = null
        this.queryParams.endDate = null
        this.queryParams2.startDate = null
        this.queryParams2.endDate = null
      }

      this.queryParams.pageNum = 1;
      this.queryParams2.pageNum = 1
      this.getList();
      this.getRecordList();
    },
    // 充值及消费记录
    goRecord() {
      this.$refs.recordList.show();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.time=[];
      this.resetForm('queryForm')
      this.refreshList()
    },

    // 违章查询
    handleQueryIllegal() {
      // 获取当前租户配置的违章查询账号
      api.illegalAcountContainType().then(res => {
        let type = res.data;
        if (type == -1) {//未配置
          this.$message('没有可用的违章查询账号,暂时无法查询');
        } else {//已配置
          this.$refs.addIllegalOrder.show(type);
        }
      })
    },

    //  创建违章工单
    addWorkOrder() {
      api.addIllegalWorkOrder().then(res => {
        this.queryParams.pageNum = 1;
        this.getList();
        this.$message({
          type: 'success',
          message: '违章查询提交成功'
        });
      })
    },

    // 获取充值消费记录
    getRecordList() {
      this.loading2 = true
      api.accountBalanceRecordList(this.queryParams2).then(res => {
        this.recordList = res.rows;
        this.total2 = res.total;
        this.loading2 = false;
      })
    },

    // 查看
    handleDetail(item) {
      this.$refs.illeaglDetail.show(item.id);
    },

    /** 查询违章工单列表 */
    getList() {
      this.loading = true
      api.illegalWorkOrderPage(this.queryParams).then(res => {
        this.basicList = res.rows;
        this.total = res.total;
        this.loading = false
      }).catch(() => {
        this.loading = false
      })
    },
    // 获取账户余额信息
    getAccountInfo() {
      api.accountBalanceInfo().then(res => {
        this.balance = res.data.balance;
      })
    }
  },
}
</script>

<style scoped>
.customer_card_1 {
  background-color: #fff;
  padding: 20px;
  margin: 15px 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}
</style>
